package com.china08.yxyapi.entity.mg.res;

import java.io.IOException;
import java.sql.Timestamp;
import java.util.Date;

import javax.persistence.Id;
import javax.persistence.Transient;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;

/**
 * 
 * 题库
 *
 */
@Document(collection = "yxy.res.ques")
public class YxyResQues {

    private static final Logger LOGGER = LoggerFactory.getLogger(YxyResQues.class);

    @Id
    private String id;
    // some properties
    @Field(value = "difficulty_level")
    @JsonProperty(value = "difficult_level")
    private String difficultyLevel;

    @Field(value = "difficulty_xs")
    @JsonProperty(value = "difficult_xs")
    private Float difficultyXishu = 0f;

    @Field(value = "ability_level")
    @JsonProperty(value = "ability_level")
    private String abilityLevel;

    @Field(value = "knowledge_ids")
    private String knowledgeIds;

    @Field(value = "know_full_ids")
    private String knowFullIds;

    @Field(value = "knowledge_texts")
    private String knowledgeTexts;

    @Field(value = "exam_ids")
    private String examIds;

    @Field(value = "exam_full_ids")
    private String examFullIds;

    @Field(value = "exam_texts")
    private String examTexts;

    @Field(value = "src_area_id")
    private String srcAreaId;

    @Field(value = "src_year")
    private String srcYear;

    @Field(value = "src_ab")
    private String srcAb;

    @Field(value = "src_type")
    private String srcType;

    @Field(value = "src_name")
    private String srcName;

    @Field(value = "question_type")
    private String questionType;

    @Field(value = "question_score")
    private String questionScore;

    @Field(value = "body")
    private String body;

    @Transient
    private Object quesBody;

    @Field(value = "question_no")
    private String questionNo;

    @Field(value = "flag")
    private String flag;

    @Field(value = "old_ids")
    private String oldIds;

    @Field(value = "docurl")
    private String docUrl;

    // COMMENT '1:删除，0：未删除
    @Field(value = "delete_flag")
    private String deleteFlag;

    @Field(value = "phase")
    private String phase;

    @Field(value = "subject")
    private String subject;

    @Field(value = "oid")
    private String oid;

    @Field(value = "question_time")
    private Integer questionTime;

    @Field(value = "created")
    private Date created;

    @Field(value = "created_by")
    private String createdBy;

    @Field(value = "modified")
    private Date modified;

    @Field(value = "modified_by")
    private String modifiedBy;

    // 0为导入 1为导入
    // ## 如果没有这个字段也是未导入
    @Field(value = "syc_es_flag")
    private Integer sycEsFlag = 0;

    // 查看范围 0：私有 1：学校 2： 教育云
    @Field(value = "view_scope")
    private Integer viewScope = 2;

    // 作业系统使用次数
    @Indexed
    @Field(value = "homework_use_count")
    private Long homeworkUseCount;

    // 作业系统收藏次数
    @Indexed
    @Field(value = "homework_favorite_count")
    private Long homeworkFavoriteCount;

    // getter setter
    public Object getQuesBody() throws JsonParseException, JsonMappingException, IOException {
        try {
            JacksonXmlModule module = new JacksonXmlModule();
            module.setDefaultUseWrapper(true);
            XmlMapper xmlMapper = new XmlMapper(module);
            this.body = this.body.replace(",yxup", "https://yx-tiku-img.oss-cn-beijing.aliyuncs.com/yxup");
            this.body = this.body.replace("img.xueshentong.com", "yx-tiku-img.oss-cn-beijing.aliyuncs.com");
            this.body = this.body.replace("src=\"\\quiz",
                    "src=\"https://yx-tiku-img.oss-cn-beijing.aliyuncs.com\\quiz");

            this.quesBody = xmlMapper.readValue(this.body, AllTemplate.class);
        } catch (Exception e) {
            LOGGER.error("ques(" + this.oldIds + ")-->quesBody 转换（template）异常!(tyw)", e);
        }
        return this.quesBody;
    }

    public Integer getQuestionTime() {
        return questionTime;
    }

    public void setQuestionTime(Integer questionTime) {
        this.questionTime = questionTime;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getPhase() {
        return phase;
    }

    public void setPhase(String phase) {
        this.phase = phase;
    }

    public String getSubject() {
        return subject;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    public String getOid() {
        return oid;
    }

    public void setOid(String oid) {
        this.oid = oid;
    }

    public String getDifficultyLevel() {
        return difficultyLevel;
    }

    public void setDifficultyLevel(String difficultyLevel) {
        this.difficultyLevel = difficultyLevel;
    }

    public Float getDifficultyXishu() {
        return difficultyXishu;
    }

    public void setDifficultyXishu(Float difficultyXishu) {
        this.difficultyXishu = difficultyXishu;
    }

    public String getAbilityLevel() {
        return abilityLevel;
    }

    public void setAbilityLevel(String abilityLevel) {
        this.abilityLevel = abilityLevel;
    }

    public String getKnowledgeIds() {
        return knowledgeIds;
    }

    public void setKnowledgeIds(String knowledgeIds) {
        this.knowledgeIds = knowledgeIds;
    }

    public String getKnowFullIds() {
        return knowFullIds;
    }

    public void setKnowFullIds(String knowFullIds) {
        this.knowFullIds = knowFullIds;
    }

    public String getKnowledgeTexts() {
        return knowledgeTexts;
    }

    public void setKnowledgeTexts(String knowledgeTexts) {
        this.knowledgeTexts = knowledgeTexts;
    }

    public String getExamIds() {
        return examIds;
    }

    public void setExamIds(String examIds) {
        this.examIds = examIds;
    }

    public String getExamFullIds() {
        return examFullIds;
    }

    public void setExamFullIds(String examFullIds) {
        this.examFullIds = examFullIds;
    }

    public String getExamTexts() {
        return examTexts;
    }

    public void setExamTexts(String examTexts) {
        this.examTexts = examTexts;
    }

    public String getSrcAreaId() {
        return srcAreaId;
    }

    public void setSrcAreaId(String srcAreaId) {
        this.srcAreaId = srcAreaId;
    }

    public String getSrcYear() {
        return srcYear;
    }

    public void setSrcYear(String srcYear) {
        this.srcYear = srcYear;
    }

    public String getSrcAb() {
        return srcAb;
    }

    public void setSrcAb(String srcAb) {
        this.srcAb = srcAb;
    }

    public String getSrcType() {
        return srcType;
    }

    public void setSrcType(String srcType) {
        this.srcType = srcType;
    }

    public String getSrcName() {
        return srcName;
    }

    public void setSrcName(String srcName) {
        this.srcName = srcName;
    }

    public String getQuestionType() {
        return questionType;
    }

    public void setQuestionType(String questionType) {
        this.questionType = questionType;
    }

    public String getQuestionScore() {
        return questionScore;
    }

    public void setQuestionScore(String questionScore) {
        this.questionScore = questionScore;
    }

    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }

    public String getQuestionNo() {
        return questionNo;
    }

    public void setQuestionNo(String questionNo) {
        this.questionNo = questionNo;
    }

    public String getFlag() {
        return flag;
    }

    public void setFlag(String flag) {
        this.flag = flag;
    }

    public String getOldIds() {
        return oldIds;
    }

    public void setOldIds(String oldIds) {
        this.oldIds = oldIds;
    }

    public String getDocUrl() {
        return docUrl;
    }

    public void setDocUrl(String docUrl) {
        this.docUrl = docUrl;
    }

    public String getDeleteFlag() {
        return deleteFlag;
    }

    public void setDeleteFlag(String deleteFlag) {
        this.deleteFlag = deleteFlag;
    }

    public void setQuesBody(Object quesBody) {
        this.quesBody = quesBody;
    }

    public Date getCreated() {
        return created;
    }

    public void setCreated(Timestamp created) {
        this.created = created;
    }

    public String getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(String createdBy) {
        this.createdBy = createdBy;
    }

    public Date getModified() {
        return modified;
    }

    public void setModified(Timestamp modified) {
        this.modified = modified;
    }

    public String getModifiedBy() {
        return modifiedBy;
    }

    public void setModifiedBy(String modifiedBy) {
        this.modifiedBy = modifiedBy;
    }

    public Integer getSycEsFlag() {
        return sycEsFlag;
    }

    public void setSycEsFlag(Integer sycEsFlag) {
        this.sycEsFlag = sycEsFlag;
    }

    public Integer getViewScope() {
        return viewScope;
    }

    public void setViewScope(Integer viewScope) {
        this.viewScope = viewScope;
    }

    public void setCreated(Date created) {
        this.created = created;
    }

    public void setModified(Date modified) {
        this.modified = modified;
    }

    public Long getHomeworkUseCount() {
        return homeworkUseCount;
    }

    public void setHomeworkUseCount(Long homeworkUseCount) {
        this.homeworkUseCount = homeworkUseCount;
    }

    public Long getHomeworkFavoriteCount() {
        return homeworkFavoriteCount;
    }

    public void setHomeworkFavoriteCount(Long homeworkFavoriteCount) {
        this.homeworkFavoriteCount = homeworkFavoriteCount;
    }

}
